package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsTopicMapper;
import com.qf.pojo.DtsTopic;
import com.qf.service.DtsTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/25 9:22
 */
@Service
public class DtsTopicServiceImpl implements DtsTopicService {

    @Autowired
    private DtsTopicMapper dtsTopicMapper;

    /**
     * 专题管理显示
     * @param title
     * @param subtitle
     * @param sort
     * @param order
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<DtsTopic> findListByQuery(String title, String subtitle, String sort, String order, Integer page, Integer limit) {
        return dtsTopicMapper.selectPage(new Page<DtsTopic>(page,limit)
                ,new QueryWrapper<DtsTopic>()
                        .like(!StringUtils.isEmpty(title),"title",title)
                        .like(!StringUtils.isEmpty(subtitle),"subtitle",subtitle)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort)
        );
    }

    /**
     * 专题添加
     * @param dtsTopic
     * @return
     */
    @Override
    public DtsTopic create(DtsTopic dtsTopic) {
        dtsTopicMapper.insert(dtsTopic);
        return dtsTopic;
    }

    /**
     * 更新
     * @param dtsTopic
     * @return
     */
    @Override
    public DtsTopic update(DtsTopic dtsTopic) {
        dtsTopicMapper.updateById(dtsTopic);
        return dtsTopic;
    }

    /**
     * 删除
     * @param dtsTopic
     * @return
     */
    @Override
    public DtsTopic delete(DtsTopic dtsTopic) {
        dtsTopicMapper.deleteById(dtsTopic);
        return dtsTopic;
    }
}
